package com.liuzh.deviceinfo.analyzer;

import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.lifecycle.LiveData;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.e;
import androidx.recyclerview.widget.RecyclerView.z;
import b.n.l;
import c.d.a.a.c.j;
import c.d.a.a.c.k;
import c.d.a.a.f.b.d;
import c.h.a.w.c;
import c.h.a.w.k.h;
import c.h.a.w.k.i;
import c.h.a.w.m.g;
import com.airbnb.lottie.LottieAnimationView;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.data.PieEntry;
import com.liuzh.deviceinfo.DeviceInfoApp;
import com.liuzh.deviceinfo.analyzer.view.BaseFloatingDetailView;
import com.liuzh.deviceinfo.analyzer.view.LargeFileFloatingView;
import com.liuzh.deviceinfo.analyzer.view.RedundantFileFloatingView;
import com.liuzh.deviceinfo.base.BaseActivity;
import com.liuzh.deviceinfo.pro.ProActivity;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;

public class StorageAnalyzeActivity extends BaseActivity implements c.h.a.w.l.b.a, c.h.a.w.e.a {
    public static final /* synthetic */ int D = 0;
    public RedundantFileFloatingView A;
    public LargeFileFloatingView B;
    public g C;
    public View q;
    public boolean r = false;
    public RecyclerView s;
    public h t;
    public b u;
    public FrameLayout v;
    public LottieAnimationView w;
    public List<i> x = new ArrayList();
    public c.h.a.w.l.b y;
    public View z;

    public class a extends c.h.b.a.a.b {
        public void b() {
            c.f.a.a.a.a.z("ad_st_ana");
        }

        public void c(String str) {
            if (!StorageAnalyzeActivity.this.x.isEmpty()) {
                int i = 0;
                while (i < StorageAnalyzeActivity.this.x.size()) {
                    if (((i) StorageAnalyzeActivity.this.x.get(i)).d == 4) {
                        break;
                    }
                    i++;
                }
                i = -1;
                if (i != -1) {
                    StorageAnalyzeActivity.this.u.d(i);
                }
            }
            ProActivity.G(StorageAnalyzeActivity.this);
        }

        public void d(String str) {
            c.f.a.a.a.a.x("ad_st_ana", str);
        }

        public void e(View view) {
            StorageAnalyzeActivity storageAnalyzeActivity = StorageAnalyzeActivity.this;
            storageAnalyzeActivity.q = view;
            if (!storageAnalyzeActivity.x.isEmpty()) {
                StorageAnalyzeActivity.this.u.d(1);
            }
        }
    }

    public class b extends e<z> {
        public LayoutInflater c;

        public class a extends AnimatorListenerAdapter {
            public a(b bVar) {
            }
        }

        public int a() {
            return StorageAnalyzeActivity.this.x.size();
        }

        public int c(int i) {
            return ((i) StorageAnalyzeActivity.this.x.get(i)).d;
        }

        public void f(z zVar, int i) {
            if (zVar instanceof c.h.a.w.j.b) {
                i iVar = (i) StorageAnalyzeActivity.this.x.get(i);
                c.h.a.w.j.b bVar = (c.h.a.w.j.b) zVar;
                bVar.t.setText(iVar.a);
                bVar.v.setText(iVar.c);
                bVar.u.setText(iVar.b.a());
                bVar.a.setOnClickListener(new c(this, iVar, bVar, i));
            } else if (zVar instanceof c.h.a.w.j.c) {
                c.h.a.w.j.c cVar = (c.h.a.w.j.c) zVar;
                h hVar = StorageAnalyzeActivity.this.t;
                if (hVar.f == null) {
                    hVar.f = new l();
                }
                Object obj = hVar.f.d;
                if (obj == LiveData.j) {
                    obj = null;
                }
                c.h.a.w.k.c cVar2 = (c.h.a.w.k.c) obj;
                Objects.requireNonNull(cVar);
                int[] iArr = c.h.a.w.j.c.u;
                if (cVar2 != null) {
                    String str;
                    StringBuilder stringBuilder;
                    PieChart pieChart = cVar.t;
                    pieChart.b = null;
                    pieChart.z = false;
                    pieChart.A = null;
                    pieChart.n.c = null;
                    pieChart.invalidate();
                    ArrayList arrayList = new ArrayList();
                    ArrayList arrayList2 = new ArrayList(cVar2.b);
                    Resources resources = DeviceInfoApp.c.getResources();
                    String packageName = DeviceInfoApp.c.getPackageName();
                    int i2 = 0;
                    while (true) {
                        str = "id";
                        if (i2 >= arrayList2.size()) {
                            break;
                        }
                        Pair pair = (Pair) arrayList2.get(i2);
                        if (((Float) pair.first).floatValue() >= 0.0f) {
                            arrayList.add(new PieEntry(((Float) pair.first).floatValue(), (String) pair.second));
                            stringBuilder = new StringBuilder();
                            stringBuilder.append("label");
                            stringBuilder.append(i2 + 1);
                            TextView textView = (TextView) cVar.a.findViewById(resources.getIdentifier(stringBuilder.toString(), str, packageName));
                            if (textView != null) {
                                textView.setText((CharSequence) pair.second);
                            }
                        }
                        i2++;
                    }
                    k kVar = new k(arrayList, "");
                    int length = iArr.length;
                    int[] iArr2 = new int[length];
                    int i3 = 0;
                    while (i3 < length) {
                        iArr2[i3] = b.i.c.a.b(DeviceInfoApp.c, iArr[i3]);
                        stringBuilder = c.b.a.a.a.g("color");
                        int i4 = i3 + 1;
                        stringBuilder.append(i4);
                        ImageView imageView = (ImageView) cVar.a.findViewById(resources.getIdentifier(stringBuilder.toString(), str, packageName));
                        if (imageView != null) {
                            imageView.setColorFilter(iArr2[i3]);
                        }
                        i3 = i4;
                    }
                    i = c.d.a.a.j.a.a;
                    ArrayList arrayList3 = new ArrayList();
                    for (int i5 = 0; i5 < length; i5++) {
                        arrayList3.add(Integer.valueOf(iArr2[i5]));
                    }
                    kVar.a = arrayList3;
                    kVar.j = false;
                    kVar.E0(2.0f);
                    j jVar = new j();
                    jVar.i.clear();
                    jVar.i.add(kVar);
                    jVar.a();
                    for (d g0 : jVar.i) {
                        g0.g0(false);
                    }
                    cVar.t.setData(jVar);
                    c.h.a.d0.d dVar = new c.h.a.d0.d(DeviceInfoApp.c);
                    dVar.c();
                    PieChart pieChart2 = cVar.t;
                    StringBuilder stringBuilder2 = new StringBuilder();
                    stringBuilder2.append((int) dVar.e);
                    stringBuilder2.append("%");
                    pieChart2.setCenterText(stringBuilder2.toString());
                    cVar.t.getLegend().a = false;
                    cVar.t.setDescription(null);
                    cVar.t.setDrawEntryLabels(false);
                    cVar.t.setTouchEnabled(false);
                    c.d.a.a.a.a aVar = cVar.t.u;
                    Objects.requireNonNull(aVar);
                    c.d.a.a.a.b.d dVar2 = c.d.a.a.a.b.a;
                    ObjectAnimator ofFloat = ObjectAnimator.ofFloat(aVar, "phaseX", new float[]{0.0f, 1.0f});
                    ofFloat.setInterpolator(dVar2);
                    ofFloat.setDuration((long) 800);
                    ofFloat.addUpdateListener(aVar.a);
                    ofFloat.start();
                }
            } else if (zVar instanceof c.h.a.w.j.a) {
                c.h.a.w.j.a aVar2 = (c.h.a.w.j.a) zVar;
                View view = StorageAnalyzeActivity.this.q;
                Objects.requireNonNull(aVar2);
                if (view == null) {
                    aVar2.t.removeAllViews();
                    aVar2.a.setVisibility(8);
                } else if (view.getParent() == null && aVar2.t.getChildCount() == 0) {
                    if (aVar2.a.getVisibility() != 0) {
                        aVar2.a.setVisibility(0);
                    }
                    aVar2.t.addView(view);
                }
            }
        }

        public z g(ViewGroup viewGroup, int i) {
            if (this.c == null) {
                this.c = LayoutInflater.from(StorageAnalyzeActivity.this);
            }
            if (i == 5) {
                return new c.h.a.w.j.c(this.c.inflate(2131492969, viewGroup, false));
            }
            if (i == 4) {
                return new c.h.a.w.j.a(this.c.inflate(2131492993, viewGroup, false));
            }
            return new c.h.a.w.j.b(this.c.inflate(2131492970, viewGroup, false));
        }

        public void h(c.h.a.w.j.b bVar, BaseFloatingDetailView baseFloatingDetailView, int i) {
            StorageAnalyzeActivity storageAnalyzeActivity = StorageAnalyzeActivity.this;
            if (!storageAnalyzeActivity.r && storageAnalyzeActivity.v.getChildCount() == 0) {
                StorageAnalyzeActivity.this.r = true;
                LayoutParams layoutParams = new LayoutParams(-1, -1);
                layoutParams.gravity = 17;
                StorageAnalyzeActivity.this.v.removeAllViews();
                StorageAnalyzeActivity.this.v.addView(baseFloatingDetailView, layoutParams);
                baseFloatingDetailView.setScaleX(1.1f);
                baseFloatingDetailView.setScaleY(1.1f);
                baseFloatingDetailView.setAlpha(0.0f);
                baseFloatingDetailView.animate().scaleX(1.0f).scaleY(1.0f).alpha(1.0f).setDuration(300).setInterpolator(new AccelerateDecelerateInterpolator()).setListener(new a(this)).start();
                baseFloatingDetailView.setCloseListener(new c.h.a.w.b(this, bVar, baseFloatingDetailView));
                int i2 = -1;
                for (int i3 = 0; i3 < StorageAnalyzeActivity.this.x.size(); i3++) {
                    int i4 = ((i) StorageAnalyzeActivity.this.x.get(i3)).d;
                    Object obj = (i4 == 0 || i4 == 1 || i4 == 3 || i4 == 2) ? 1 : null;
                    if (obj != null) {
                        i2++;
                    }
                    if (i == i3) {
                        break;
                    }
                }
                if (i2 != -1) {
                    h hVar = StorageAnalyzeActivity.this.t;
                    baseFloatingDetailView.d = i2;
                    baseFloatingDetailView.a = hVar;
                    if (hVar == null || hVar.b == null) {
                        com.liuzh.deviceinfo.analyzer.view.BaseFloatingDetailView.b bVar2 = baseFloatingDetailView.b;
                        if (bVar2 != null) {
                            bVar2.onClickClose();
                        } else {
                            throw new RuntimeException("close listener cant't be null");
                        }
                    }
                    baseFloatingDetailView.c();
                    baseFloatingDetailView.a();
                }
            }
        }
    }

    public static void C(Context context, String str) {
        Intent intent = new Intent(context, StorageAnalyzeActivity.class);
        intent.putExtra("analyze_path", str);
        context.startActivity(intent);
    }

    public final void A() {
        if (!c.h.a.f0.j.d.i()) {
            c.h.a.m0.i iVar = c.h.a.m0.i.a;
            iVar = c.h.a.m0.i.a;
            if (!c.h.a.m0.i.b()) {
                c.f.a.a.a.a.y("ad_st_ana");
                c.h.b.a.a.c.a(this, c.h.a.u.a.g, new a());
            }
        }
    }

    public final void B() {
        int indexOf;
        for (i iVar : this.x) {
            if (iVar.d == 2) {
                indexOf = this.x.indexOf(iVar);
                break;
            }
        }
        indexOf = -1;
        if (indexOf != -1) {
            this.u.d(indexOf);
        }
        c.h.a.v.a.b.c("analyze_dup_comp", null);
    }

    public void f(long j, boolean z, c.h.a.w.e eVar) {
        runOnUiThread(new c.h.a.w.d(this));
    }

    public void onBackPressed() {
        if (this.r) {
            View childAt = this.v.getChildAt(0);
            if (childAt instanceof BaseFloatingDetailView) {
                ((BaseFloatingDetailView) childAt).getCloseListener().onClickClose();
            }
            return;
        }
        this.e.a();
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        String stringExtra = getIntent().getStringExtra("analyze_path");
        if (TextUtils.isEmpty(stringExtra)) {
            finish();
            return;
        }
        z();
        setContentView(2131492901);
        this.w = (LottieAnimationView) findViewById(2131296350);
        this.z = findViewById(2131296346);
        this.s = (RecyclerView) findViewById(2131296830);
        this.v = (FrameLayout) findViewById(2131296569);
        this.u = new b();
        this.s.setLayoutManager(new LinearLayoutManager(1, false));
        this.s.setAdapter(this.u);
        c.h.a.w.l.c cVar = new c.h.a.w.l.c();
        this.y = cVar;
        cVar.e = this;
        Objects.requireNonNull(cVar);
        new Thread(new c.h.a.w.l.a(cVar, stringExtra)).start();
        A();
        c.h.a.v.a.b.c("analyze_show", null);
    }

    public void onDestroy() {
        super.onDestroy();
        c.h.a.w.l.b bVar = this.y;
        if (bVar != null) {
            bVar.g = true;
        }
        h hVar = this.t;
        if (hVar != null) {
            c.h.a.w.e eVar = hVar.a;
            if (eVar != null) {
                eVar.i.remove(this);
            }
            c.h.a.w.k.b bVar2 = this.t.d;
            if (bVar2 != null) {
                for (c.h.a.w.e eVar2 : bVar2.a) {
                    eVar2.i.remove(bVar2);
                }
                bVar2.a.clear();
            }
            c.h.a.w.k.e eVar3 = this.t.e;
            if (eVar3 != null) {
                eVar3.f = true;
                synchronized (c.h.a.w.k.e.class) {
                    for (Entry value : eVar3.b.entrySet()) {
                        for (c.h.a.w.e eVar4 : (List) value.getValue()) {
                            eVar4.i.remove(eVar3);
                        }
                    }
                }
                eVar3.b.clear();
                eVar3.c.clear();
                eVar3.d.clear();
                eVar3.a.clear();
            }
        }
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() != 16908332) {
            return super.onOptionsItemSelected(menuItem);
        }
        onBackPressed();
        return true;
    }
}
